package com.yiwenup.leetcode.top_interview_150;

import com.yiwenup.leetcode.ListNode;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.top_interview_150
 * @Author yiwenup
 * @Date 2024-12-24 22:32:14
 * @Description https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/description/?envType=study-plan-v2&envId=top-interview-150
 */
public class No0082 {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = head;
        ListNode cur = dummyHead;
        ListNode tmp = dummyHead;
        while (cur.next != null && cur.next.next != null) {
            if (cur.next.val == cur.next.next.val) {
                tmp = cur.next.next.next;
                while (tmp != null && tmp.val == cur.next.val) {
                    tmp = tmp.next;
                }
                cur.next = tmp;
            } else {
                cur = cur.next;
            }
            tmp = cur;
        }
        return dummyHead.next;
    }
}
